import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { UsersPaginationDto } from './dto/users-pagination.dto';
import { FindDataDto } from './dto/find-data.dto';
import { UserDto } from './dto/user.dto';

@Injectable({
  providedIn: 'root',
})
export class UsersService {
  constructor(private http: HttpClient) {}

  /**
   * 查询一些用户
   * @param usersPaginationDto 分页
   */
  find(usersPaginationDto: UsersPaginationDto) {
    const { pageIndex, pageSize, keyword } = usersPaginationDto;
    return this.http.get<FindDataDto<UserDto>>('users', {
      params: {
        pageIndex: pageIndex.toString(),
        pageSize: pageSize.toString(),
        keyword,
      },
    });
  }

  /**
   * 通过用户 _id 删除用户
   * @param _id 用户 _id
   */
  // tslint:disable-next-line: variable-name
  deleteById(_id: string) {
    return this.http.delete(`users/${_id}`);
  }
}
